package com.tanhua.server.controller;

import com.tanhua.commons.constants.Constants;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Xiao
 * @date 2021/10/21
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 发送短信验证码
     * @param map
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String, String> map) {
        String mobile = map.get("phone");
        userService.sendSms(mobile);
//        return ResponseEntity.status(200).body("验证码已发送！");
        return ResponseEntity.ok("验证码已发送！");
    }

    /**
     * 登录校验
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String, String> map) {
        String mobile = map.get("phone");
        String verificationCode = map.get("verificationCode");
        Map reMap = userService.loginVerification(mobile, verificationCode);
        return ResponseEntity.ok(reMap);
    }
}
